//
//  ecgVC.m
//  massage
//
//  Created by 李志权 on 2016/12/14.
//  Copyright © 2016年 李志权. All rights reserved.
//

#import "ecgVC.h"
#import "LeftMenuView.h"
#import "AppDelegate.h"
@interface ecgVC ()<LeftMenuViewDelegate>
@property (nonatomic, strong) LeftMenuView *menuView;
@end

@implementation ecgVC
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    appDelegate.allowRotation = YES;//(以上2行代码,可以理解为打开横屏开关)
    
    [self setNewOrientation:YES];//调用转屏代码
 
    if (!self.menuView) {
        UIWindow *window = [[UIApplication sharedApplication]keyWindow];
        self.menuView = [[[LeftMenuView alloc] init] initWithContainerView:window];
        self.menuView.menuViewDelegate = self;
        //NSLog(@"----LeftMenuView0---- %@",self.menuView);
        [window addSubview:self.menuView];
        self.menuView.menuViewDelegate = self;
        self.menuView.menuTableView.highly = window.highly;
    }

    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"心电";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"按摩_icon2"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemClick)];
    
   
    
    // Do any additional setup after loading the view from its nib.
}
- (void)leftBarButtonItemClick
{
    [UIView animateWithDuration:0.25 animations:^{
        self.menuView.X = 0;
    }];
}
#pragma mark - LeftMenuViewDelegate
- (void)LeftMenuViewActionIndex:(NSString *)vType{
    [Utils leftMenuClickIndex:vType];
    [self.menuView closeLeftView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
//第三步:
//
//1.在需要强制横屏的控制器.m中添加旋转为横屏方法

- (void)setNewOrientation:(BOOL)fullscreen

{
    
    if (fullscreen) {
        
        NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
        
        [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
        
        
        
        NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
        
        [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
        
    }else{
        
        NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
        
        [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
        
        
        
        NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        
        [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
        
    }
    
}
//3.重写导航栏返回箭头按钮,拿到返回按钮点击事件
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    appDelegate.allowRotation = NO;//关闭横屏仅允许竖屏
    
    [self setNewOrientation:NO];
    if (self.tabBarController.selectedIndex!=1) {
        [self.menuView removeFromSuperview];
        [self.menuView.maskView removeFromSuperview];
        self.menuView = nil;
    }
   
}
@end
